import { Component, OnInit } from '@angular/core';
import { ThemeService } from '../../../service/theme.service';
import { ColorType, FontType, Setting, SettingService } from '../../../service/config.service';

@Component({
  selector: 'app-setting',
  templateUrl: './setting.component.html',
  styleUrls: ['./setting.component.css']
})

export class SettingComponent implements OnInit {
  foregroundPresetColors = [
    'rgb(0,204,116)',
    'rgb(0,239,0)',
    'rgb(112,130,132)',
    'rgb(0,0,0)',
    'rgb(59,35,34)',
    'rgb(255,255,255)'
  ]
  backgroundPresetColors = [
    'rgb(20,23,41)',
    'rgb(0,0,0)',
    'rgb(0,30,39)',
    'rgb(145,145,145)',
    'rgb(233,219,195)',
    'rgb(213,221,224)'
  ]
  colorList = [];
  fontList = [];
  constructor(public settingSvc: SettingService, private themeService: ThemeService) {
    for (var key in ColorType) {
      this.colorList.push(ColorType[key]);
    }
    for (var key in FontType) {
      this.fontList.push(FontType[key]);
    }
  }

  setting: Setting;
  ngOnInit(): void {
    this.setting = this.settingSvc.getConfig();
  }
  darkModeChanged() {
    this.themeService.changeTheme(this.setting.global.darkMode).then();
  }
  saveSetting() {
    this.settingSvc.saveConfig();
  }
  changeBackgroundColor(color) {
    this.setting.terminal.background = color;
  }
  changeForegroundColor(color) {
    this.setting.terminal.foreground = color;
  }
  changeFont(font) {
    this.setting.terminal.fontFamily = font;
  }
}
